﻿using GIMS.Def.Arguments;
using GIMS.Def.Operators;
using GIMS.Def.Settings;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.ComponentModel;

namespace GIMS.Def.Test
{
    /// <summary>
    ///This is a test class for CropOperatorTest and is intended
    ///to contain all CropOperatorTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CropOperatorTest
    {
        /// <summary>
        /// Reset GlobalSettings
        /// </summary>
        [TestInitialize()]
        public void MyTestInitialize()
        {
            GlobalSettings_Accessor.instance = null;
        }

        /// <summary>
        ///A test for CreateScriptPart - Crop Operator with "gravity Setting"
        ///</summary>
        [TestMethod()]
        public void CreateScriptPartTest()
        {
            CropOperator_Accessor target = new CropOperator_Accessor();
            GeometryArgument arg = target.Argument as GeometryArgument;

            target.gravitySetting.Active = true;
            GravityArgument arg1 = (GravityArgument)target.gravitySetting.Argument;
            arg1.Gravity = Gravity.center;
            arg.Width = 111;
            arg.Height = 222;
            arg.XOffset = 33;
            arg.YOffset = 44;
            string actual;
            actual = target.CreateScriptPart();
            Assert.AreEqual("-gravity center -crop 111x222+33+44", actual);
        }

        /// <summary>
        ///A test for the changed argument event
        ///</summary>
        [TestMethod()]
        [DeploymentItem("GIMS.Def.dll")]
        public void ArgumentChangedTest1()
        {
            List<string> receivedEvents = new List<string>();
            CropOperator target = new CropOperator();

            target.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                receivedEvents.Add(e.PropertyName);
            };

            ((GeometryArgument)target.Argument).Scale = 20;     //event
            ((GeometryArgument)target.Argument).SelectedGeometryType = GeometryType.percent;    //event
            Assert.AreEqual(2, receivedEvents.Count);
            Assert.AreEqual("Argument.geometry", receivedEvents[0]);
        }

        /// <summary>
        ///A test for the changed argument event - raised by changing a Setting from Inactive to Active
        ///</summary>
        [TestMethod()]
        [DeploymentItem("GIMS.Def.dll")]
        public void ArgumentChangedTest2()
        {
            List<string> receivedEvents = new List<string>();
            CropOperator target = new CropOperator();

            target.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                receivedEvents.Add(e.PropertyName);
            };

            target.Settings[0].Active = true;
            Assert.AreEqual(1, receivedEvents.Count);
            Assert.AreEqual("Setting.active", receivedEvents[0]);
        }
    }
}
